package com.grt192.mechanism.hauntedhouse;

import com.grt192.core.Mechanism;
import com.grt192.actuator.GRTSolenoid;
import com.grt192.core.Command;
import com.grt192.sensor.GRTSwitch;
import com.sun.squawk.ManifestProperty;

/**
 * Abstraction of a Mechanism on the Haunted House,
 * with 1 switch and 1 solenoid.
 * We identify them by solenoid.
 * @author data, ajc, nik.lele
 */
public class HauntedHouseMechanism extends Mechanism {

    private String switchID;
    private String solenoidID;
    private GRTSolenoid solenoid;
    private GRTSwitch sswitch;
//    private boolean extended;
    private int switchPin;
    private int solPin;

    /**
     * @deprecated  This works, not recommended-- no reason to cut switch
     * support
     */
    public HauntedHouseMechanism(int solPin) {
        //we identify mechanisms by solenoid
        solenoidID = "Solenoid" + solPin;

        solenoid = new GRTSolenoid(solPin);
        addActuator(solenoidID, solenoid);
        solenoid.start();

//        this.extended = true;
    }

    public HauntedHouseMechanism(int solPin, int switchPin) {
        this.switchPin = switchPin;
        this.solPin = solPin;

        switchID = "Switch" + switchPin;
        solenoidID = "Solenoid" + solPin;

        solenoid = new GRTSolenoid(solPin);
        sswitch = new GRTSwitch(switchPin, 50, switchID);

//        this.extended = true;
        init();
    }

    private void init() {
        addActuator(solenoidID, solenoid);
        addSensor(switchID, sswitch);

        solenoid.start();
        sswitch.start();
    }

//    public boolean isExtended() {
//        return extended;
//    }

    public void extend() {
        solenoid.enqueueCommand(new Command(GRTSolenoid.ON));
    }

    public void retract() {
        solenoid.enqueueCommand(new Command(GRTSolenoid.OFF));
    }
}
